<template>
	<div>
		<template>
			<el-table :data="tableData5" style="width: 100%">
				<el-table-column prop="cid" label="稿件id" width="100px">
				</el-table-column>
				<el-table-column prop="name" label="姓名" width="100px">
				</el-table-column>
				<el-table-column prop="academy" label="学院">
				</el-table-column>
				<el-table-column prop="class" label="班级">
				</el-table-column>
				<el-table-column prop="msg" label="留言">
				</el-table-column>
				<el-table-column prop="count1" label="浏览数">
				</el-table-column>
				<el-table-column prop="count2" label="点赞数">
				</el-table-column>
				<el-table-column prop="count3" label="评论数">
				</el-table-column>
				<el-table-column prop="datetime" label="时间" width="160px">
				</el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">查看</el-button>
					</template>
				</el-table-column>
			</el-table>

			<!-- :visible.sync="dialogVisible" -->
			<el-dialog title="稿件内容" :visible.sync="dialogVisible" top="20px" width="70%">
				<div id="pdfDom" v-html="showContent"></div>
				<!-- 定义按钮 -->
				<span slot="footer" class="dialog-footer">
					<el-button type="success" @click="exportPdf()">导出PDF</el-button>
					<el-button type="info" @click="method3()">重新审核</el-button>
					<el-button @click="dialogVisible = false;seeid = ''">取消</el-button>
				</span>
			</el-dialog>
		</template>
		<div class="block" style="margin-top: 10px;">
			<el-pagination background layout="prev, pager, next" :page-size='8' :total="total" :current-page="currentPage"
			 @current-change="handleCurrentChange">
			</el-pagination>
		</div>
	</div>
</template>

<script>

	export default {
		name: 'filterTable',
		data() {
			return {
				tableData5: [{
					'cid': 1,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 2,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 3,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 4,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 5,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 6,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 7,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}, {
					'cid': 8,
					'name': '张三',
					'academy': '家里蹲学院',
					'class': '18网络',
					'msg': '匿名播出',
					'datetime': '2019-05-12 00:00:00'
				}],
				total: 60,
				currentPage: 1,
				dialogVisible: false,
				showContent: '',
				seeid: '',
				htmlTitle: 'test'
			}
		},
		created() {
			this.axios.get(this.server + '/goodCon/getMsg?page=1&token=' + this.store.getters.token).then(res => {
				if (res == '0') {
					this.$message.error("获取数据失败！")
				} else {
					this.tableData5 = res.data.tableData
					this.total = res.data.total
				}
			}, res => {
				this.$message.error("网络错误！")
			})
		},
		methods: {
			exportPdf() {
				this.$message.info("文件正在导出，请稍等！")
				this.axios.get(this.server + '/goodCon/exportPdf?id=' + this.seeid + '&token=' + this.store.getters.token,{
					responseType: "blob"
				}).then(res => {
					if(res.data != '0') {
						this.$message.info("文件已导出，正在打包，请稍后！")
						const _res = res.data;
						let blob = new Blob([_res], {type: 'application/pdf'});
						let downloadElement = document.createElement("a");
						let href = window.URL.createObjectURL(blob); //创建下载的链接
						downloadElement.href = href;
						// downloadElement.download = fileName; //下载后文件名
						downloadElement.download = this.seeid + '号稿件'; //下载后文件名
						document.body.appendChild(downloadElement);
						downloadElement.click(); //点击下载
						document.body.removeChild(downloadElement); //下载完成移除元素
						window.URL.revokeObjectURL(href); //释放掉blob对象
						this.$message.success("文件导出成功！")
						
						this.axios.get(this.server + '/goodCon/delPdf?id=' + this.seeid + '&token=' + this.store.getters.token).then(res => {
							
						},res => {
							
						})
					}else {
						this.$message.info("文件已导出，正在打包，请稍后！")
						this.getPdf()
					}

				},res => {
					this.$message.info("文件已导出，正在打包，请稍后！")
					this.getPdf()
				})
			},
			handleEdit(index, row) {
				this.$message.info("正在获取，请稍后！")
				this.axios.get(this.server + '/unCon/getConById?id=' + row.cid + '&token=' + this.store.getters.token).then(res => {
					if (res.data != '0') {
						this.showContent = res.data
						this.dialogVisible = true
						this.seeid = row.cid
						this.htmlTitle = row.cid + "号稿件"
					} else {
						this.$message.error("获取稿件内容失败！")
						this.seeid = ''
					}
				}, res => {
					this.$message.error("网络连接失败！")
					this.seeid = ''
				})
			},
			handleCurrentChange(val) {
				this.axios.get(this.server + '/goodCon/getMsg?page=' + val + '&token=' + this.store.getters.token).then(res => {
					if (res == '0') {
						this.$message.error("获取数据失败！")
					} else {
						this.tableData5 = res.data.tableData
						this.total = res.data.total
					}
				}, res => {
					this.$message.error("网络错误！")
				})
			},
			method3() {
				if (this.seeid != '') {
					this.axios.get(this.server + '/unCon/updateStatus?id=' + this.seeid + '&status=0&token=' + this.store.getters.token)
						.then(res => {
							if (res.data == '1') {
								this.$message.success("已回退到未审核状态，请注意查看！")
								this.dialogVisible = false
								this.axios.get(this.server + '/goodCon/getMsg?page=1&token=' + this.store.getters.token).then(res => {
									if (res == '0') {
										this.$message.error("获取数据失败！")
									} else {
										this.tableData5 = res.data.tableData
										this.total = res.data.total
									}
								}, res => {
									this.$message.error("网络错误！")
								})
							} else {
								this.$message.error("审核失败！")
							}
						}, res => {
							this.$message.error("请检查网络！")
						})
				} else {
					this.$message.error("请先阅读稿件！")
				}
			}
		}
	}
</script>

<style scoped>

</style>
